package com.jinmdz.fmis.dao.dao;

import com.jinmdz.fmis.dao.dao.provider.ColdStorageProvider;
import com.jinmdz.fmis.dao.model.coldstorage.ColdStorageViewItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.ArrayList;

/**
 * 冷藏Dao
 *
 * @author GuanKui
 * @date 2020/2/11 16:26
 */
public interface ColdStorageDao {

    /**
     * 按照主键获取冷藏信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-02-20 14:54
     */
    @SelectProvider(type = ColdStorageProvider.class, method = "getColdStorageViewById")
    ColdStorageViewItem getColdStorageViewById(@Param("id") Integer id);

    /**
     * 按照业务编码查询冷藏信息
     *
     * @param businessCode 业务编码
     * @return
     * @author LiCongLu
     * @date 2020-02-16 15:30
     */
    @SelectProvider(type = ColdStorageProvider.class, method = "listColdStorageViewByBusinessCode")
    ArrayList<ColdStorageViewItem> listColdStorageViewByBusinessCode(@Param("businessCode") String businessCode);

    /**
     * 通过非占用等条件获取占用设备冷藏业务主键
     *
     * @param equipmentId 设备主键
     * @param businessId  原冷藏信息主键
     * @param outState    出藏状态
     * @return
     * @author LiCongLu
     * @date 2020-02-26 15:58
     */
    @Select(" select id from cold_storage where deleted=0 and equipment_id = #{equipmentId} and id != IFNULL(#{businessId},0) and process_state_code != #{outState} limit 1 ")
    @ResultType(Integer.class)
    Integer getBusinessIdForEquipmentId(@Param("equipmentId") Integer equipmentId, @Param("businessId") Integer businessId, @Param("outState") Integer outState);
}
